package com.ebt.m.customer.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageButton;

import com.ebt.m.R;

/**
 * Created by Rick.Wang on 2016/4/29.
 */
public class CustomerAllTitleView extends FrameLayout implements View.OnClickListener{

    //view
    private ViewGroup mContent;
    private ImageButton mViewBack;
    private ImageButton mViewDelete;
    private ImageButton mViewEdit;
    private ImageButton mViewAdd;
    private OnTitleOperatedListener mListener;

    public CustomerAllTitleView(Context context) {
        this(context, null);
    }

    public CustomerAllTitleView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContent = (ViewGroup) inflate(context, R.layout.view_customer_all_title, this);
        mViewBack = (ImageButton) mContent.findViewById(R.id.back);
        mViewAdd = (ImageButton) mContent.findViewById(R.id.add);
        mViewEdit = (ImageButton) mContent.findViewById(R.id.edit);
        mViewDelete = (ImageButton) mContent.findViewById(R.id.delete);

        mViewBack.setOnClickListener(this);
        mViewAdd.setOnClickListener(this);
        mViewEdit.setOnClickListener(this);
        mViewDelete.setOnClickListener(this);
    }

    public void setOnTitleOperatedListener(OnTitleOperatedListener listener){
        mListener = listener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                if(mListener != null){
                    mListener.onBack();
                }
                break;
            case R.id.add:
                if(mListener != null){
                    mListener.onAdd();
                }
                break;
            case R.id.edit:
                if(mListener != null){
                    mListener.onEdit();
                }
                break;
            case R.id.delete:
                if(mListener != null){
                    mListener.onDelete();
                }
                break;
        }
    }

    public interface OnTitleOperatedListener{
        void onBack();
        void onAdd();
        void onEdit();
        void onDelete();
    }

}